Vue.component('ifm', {
    template: '<div>' +
        '<div v-on:click="open()">' +
        '<slot >' +
        '<div style="display:inline-block;cursor:pointer;color:#f60;">标题</div>' +
        '</slot>' +
        '</div>' +
        '<div class="edit-fields-modal modal-mask {{addClass}}" v-show="show" transition="modal">' +
        '<div class="modal-wrapper">' +
        '<div class="modal-container">' +
        '<div class="modal-header">' +
        '<slot name="header"><h4>{{deliverObj.title}}</h4></slot>' +
        '<em class="close" @click="close(1)"><i></i></em>' +
        '</div>' +
        '<div class="modal-body">' +
        '<iframe style="width:100%;border:0px;height:400px;background: white;" v-bind:src="deliverObj.url"></iframe>' +
        '</div>' +
        '<div class="modal-footer">' +
        '<slot name="footer">' +
        '<a class="revision-btn" href="javascript:;" @click="close(0)">确定</a>' +
        '</slot>' +
        '</div>' +
        '</div>' +
        '</div>' +
        '</div>' +
        '</div>',
    data: function() {
        return {
            show: false
        }
    },
    props: {
        addClass: {
            type: String,
            required: false,
            default: ''
        },
        style: Object,
        init: Function,
        beforeClose: Function,
        deliverObj: Object,
        deliverMsg: Object
    },
    ready: function() {
        if (typeof this.init === 'function') {
            this.init();
        }
    },
    methods: {
        open: function() {
            $(this.$el).find("iframe").attr("src", this.deliverObj.src);

            //闭包
            var cb = (function cb(that) {
                var tmp = that.deliverMsg;
                return function temp() {
                    var msg = tmp;
                    if (this.contentWindow.vm != undefined && this.contentWindow != undefined && this.contentWindow.vm.initDialogData != undefined) {
                        this.contentWindow.vm.initDialogData(msg);
                    }
                }
            })(this);
            $(this.$el).find("iframe")[0].onload = cb;
            this.show = true;
        },
        close: function(flag) {
            if (typeof this.beforeClose === 'function') {
                if (this.beforeClose() === false) {
                    return;
                }
            }
            this.show = false;

            if (flag === 0) {
                //vm
                if (vm != undefined && vm.fatherCb != undefined &&
                    $(this.$el).find("iframe")[0].contentWindow.vm != undefined) {
                    if (this.deliverObj.cb !== undefined && vm[this.deliverObj.cb] !== undefined) {
                        vm[this.deliverObj.cb]($(this.$el).find("iframe")[0].contentWindow.vm);
                    } else {
                        vm.fatherCb($(this.$el).find("iframe")[0].contentWindow.vm);
                    }
                }
            }
            $(this.$el).find("iframe").attr("src", "");
        }
    }
});